
#include "linux_def.h"
#include "core.h"
#include "log.h"
#include "cycle.h"

pid_t	g_pid;

int main(int argc, char** argv)
{
	int	i;
	log_t	*log;
	cycle_t	*cycle, init_cycle;

	time_init();	

	g_pid = getpid();

	if ((log = log_init()) == NULL){
		fprintf(stderr, "log_init() failed.\n");
		exit(-1);
	}

	//crc32_init();
	
	memset(&init_cycle, 0, sizeof(cycle_t));	
	init_cycle.log = log;

	g_cycle = &init_cycle;

	//创建1024空间大小为cycle_t对象, 只存放一个cycle_t对象
	init_cycle.pool = create_pool(1024, log);
	if (init_cycle.pool == NULL){
		fprintf(stderr, "create_pool() failed.\n");
		exit(-1);
	}

	//初始化init_cycle，包含结构体中的成员
	cycle = g_init_cycle(&init_cycle);
	if (cycle == NULL){
		fprintf(stderr, "init_cycle() failed.\n");
		exit(-1);
	}

	g_cycle = cycle;

	if (init_signals() == -1){
		fprintf(stderr, "init_signal() failed.\n");
		exit(-1);
	}

	process = PROCESS_MASTER;

	master_process_cycle(cycle);
    
	return 0;
}
